package algorithm.sort;

public class ChoiceSort {
    public static void main(String[] args) {
        int[] nums = NumberUtil.getNums(10, 0, 100);
        NumberUtil.printNum(nums);
        System.out.println("===================================");
        int[] ints = sortArray(nums);
        System.out.println("===================================");
        NumberUtil.printNum(ints);
    }

    public static int[] sortArray(int[] nums) {
        if (nums.length == 0) {
            return nums;
        }
        for (int i = 0; i < nums.length; i++) {
            int minIndex = i;
            for (int j = i; j < nums.length; j++) {
                if (nums[j] < nums[minIndex]) {
                    minIndex = j;
                }
            }
            System.out.println("min num: " + nums[minIndex]);
            int temp = nums[minIndex];
            nums[minIndex] = nums[i];
            nums[i] = temp;
            NumberUtil.printNum(nums);
            System.out.println("---------------");
        }
        return nums;
    }
}
